package src

import "sync"

type MyMutexChannel struct {
	C      chan int
	closed bool
	mutex  sync.Mutex
}

func NewMyMutexChannel() *MyMutexChannel {
	return &MyMutexChannel{C: make(chan int)}
}

func (mmc *MyMutexChannel) SafeClose() {
	mmc.mutex.Lock()
	defer mmc.mutex.Unlock()

	if !mmc.closed {
		close(mmc.C)
		mmc.closed = true
	}
}

func (mmc *MyMutexChannel) IsClosed() bool {
	mmc.mutex.Lock()
	defer mmc.mutex.Unlock()
	return mmc.closed
}
